<#include "../comm/_layout.html"/>
<style type="text/css">
#postList {
	width: 100%;
	height: 80%;
	float: left;
}

#postAdd {
	width: 100%;
	height: 20%;
	background-color: #fff;
	float: left;
}

table {
	color: #333;
	border-color: #fff;
	width: 100%;
}

.tdd:hover {
	background: #f55;
}
</style>
<@layout>

<script type="text/javascript">
$(document).ready(function(){
		$("#save").click(function(){
		if($("#content").val()==""){
			alert("内容不能为空");
		}else{
	 		var objStr='{"authorId":'
	 			+${session.sessionUser.id!1}
	 			+',"content":'
	 			+$("#content").val()
	 			+'}';
	 			
		$.ajax({
		type:'post',
		url:'${ctx_path}/p/savePost',
		data:{ objStr:objStr},
		dataType:'json',
		success:function(msg){
				if(msg=="0"){
					alert("发表失败");		
				}else{
					window.location="${ctx_path}/";
				}
			}
		}) 
		}	
		});
});

function like(postid){
	$.ajax({
		type:'post',
		url:'${ctx_path}/p/likePost',
		data:{postId:postid,userId:${session.sessionUser.id!1},like:true},
		dataType:'text',
		success:function(msg){
				if(msg=="0"){
					alert("失败");		
				}else{
					window.location="${ctx_path}/";
				}
			}
		});
}

function unlike(postid){
	$.ajax({
		type:'post',
		url:'${ctx_path}/p/likePost',
		data:{postId:postid,userId:${session.sessionUser.id!1},like:false},
		dataType:'text',
		success:function(msg){
				if(msg=="0"){
					alert("失败");		
				}else{
					window.location="${ctx_path}/";
				}
			}
		});
}
</script>

<#if session.sessionUser??>
<h3>
	当前登录：${session.sessionUser.phone!}&nbsp|&nbsp<a href="${ctx_path}/u/logout">注销</a>
</h3>
<#else> </#if>


<div id="postAdd">
	<h1>发表</h1>
	<input type="text" id="content" /> <input type="button" id="save" value="发表" />
</div>

<div id="postList">
	<h1>秘密列表</h1>
	<table border="1">
		<tr>
			<th>序号</th>
			<th>内容</th>
			<th>热度</th>
			<th>已赞</th>
			<th>发帖人</th>
			<th>时间</th>
			<th>操作</th>
		</tr>
		<#list posts as post>
		<tr class="tdd">
			<td>${post_index+1}</td>
			<td>${post.content!}</td>
			<td>${post.likeCount!}</td>
			<td>${post.liked!0}</td>
			<td>${post.authorId!}</td>
			<td>${post.createTime!}</td>
			<td><a href="javascript:void(0);" onclick="like(${post.id!})"> 赞一个 </a> 
			|<br> <a href="javascript:void(0);" onclick="unlike(${post.id!})"> 取消赞 </a>
			|<a href="${ctx_path}/p/coment/${post.id!}"> 回复 </a></td>
		</tr>
		</#list>
	</table>
</div>
</@layout>



